home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Image Encoders and Decoders / Setting JPEG Compression Level / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2002-02-15  |  2.6 KB  |  88 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, GDIPAPI, GDIPOBJ, GDIPUTIL;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Memo1: TMemo;
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.dfm}
  25.  
  26. procedure TForm1.FormCreate(Sender: TObject);
  27. var
  28.   encoderClsid: TGUID;
  29.   encoderParameters: TEncoderParameters;
  30.   quality: ULONG;
  31.   stat: TStatus;
  32.   Image: TGPImage;
  33. begin
  34.  
  35.    // Get an image from the disk.
  36.    Image := TGPImage.Create('..\..\Media\GrapeBunch.bmp');
  37.  
  38.    // Get the CLSID of the JPEG encoder.
  39.    GetEncoderClsid('image/jpeg', encoderClsid);
  40.  
  41.    // Before we call Image::Save, we must initialize an
  42.    // EncoderParameters object. The EncoderParameters object
  43.    // has an array of EncoderParameter objects. In this
  44.    // case, there is only one EncoderParameter object in the array.
  45.    // The one EncoderParameter object has an array of values.
  46.    // In this case, there is only one value (of type ULONG)
  47.    // in the array. We will let this value vary from 0 to 100.
  48.  
  49.    encoderParameters.Count := 1;
  50.    encoderParameters.Parameter[0].Guid := EncoderQuality;
  51.    encoderParameters.Parameter[0].Type_ := EncoderParameterValueTypeLong;
  52.    encoderParameters.Parameter[0].NumberOfValues := 1;
  53.  
  54.    // Save the image as a JPEG with quality level 0.
  55.    quality := 0;
  56.    encoderParameters.Parameter[0].Value := @quality;
  57.    stat := image.Save('Shapes001.jpg', encoderClsid, @encoderParameters);
  58.  
  59.    if(stat = Ok) then
  60.       Memo1.Lines.Add('Shapes001.jpg saved successfully.')
  61.    else
  62.       Memo1.Lines.Add(GetStatus(Stat) + ' Attempt to save Shapes001.jpg failed.');
  63.  
  64.    // Save the image as a JPEG with quality level 50.
  65.    quality := 50;
  66.    encoderParameters.Parameter[0].Value := @quality;
  67.    stat := image.Save('Shapes050.jpg', encoderClsid, @encoderParameters);
  68.  
  69.    if(stat = Ok) then
  70.       Memo1.Lines.Add('Shapes050.jpg saved successfully.')
  71.    else
  72.       Memo1.Lines.Add(GetStatus(Stat) + ' Attempt to save Shapes050.jpg failed.');
  73.  
  74.       // Save the image as a JPEG with quality level 100.
  75.    quality := 100;
  76.    encoderParameters.Parameter[0].Value := @quality;
  77.    stat := image.Save('Shapes100.jpg', encoderClsid, @encoderParameters);
  78.  
  79.    if(stat = Ok) then
  80.       memo1.Lines.Add('Shapes100.jpg saved successfully.')
  81.    else
  82.       memo1.Lines.Add(GetStatus(Stat) + ' Attempt to save Shapes100.jpg failed.');
  83.  
  84.    image.Free;
  85. end;
  86.  
  87. end.
  88.